"""
姓名:张三,李四,王五,小明,小红
成绩:张三,语文(100),10;李四,语文(30),1;王五,语文(60),4;小明,语文(66),20;小红,语文(99),3
要求：提取成绩，并按成绩降序排列
输出到文件的格式：
科目 姓名 成绩 编号 是否及格
语文  张三 1oo 10  是
语文  小红 99  3   是
"""
text= open("q1.txt", "r", encoding="utf-8")
text.readline()
text2= text.readline()
text.close()
# print(text2)

tx=text2.split(":")
# print("正文:",tx[1])
xx = tx[1]
a1 = xx.split("\n")
a=a1[0]

lists=a.split(";")
# print("lists=",lists)
names=[]
scores=[]
numbers=[]

for i in lists:
    # print("i=",i)
    b = i.split(",")
    # print("b=",b)
    names.append(b[0])
    cc = b[1]
    scores.append(cc[3:len(cc)-1])
    numbers.append(b[2])

print(names)
print(scores)
print(numbers)
print("_"*8**2)

class students:
    sub = "语文"
    def __init__(self,name,score,num):
        self.name=name
        self.score=score
        self.num=num
        if int(score) >= 60:
            self.aa = "是"
        else:
            self.aa = "否"
str1=""
for i in range(len(names)):
    stu = students(names[i], scores[i], numbers[i])
    # print(stu.sub,stu.name, stu.score, stu.num, stu.aa)
    yy = stu.sub+" "+stu.name+" "+stu.score+" "+stu.num+" "+stu.aa
    str1=str1+yy+"\n"
print(str1)

tt = open("q2.txt", "w", encoding="utf-8")
tt.write(str1)
tt.close()
